#include "barrier.h"
#include "config.h"
#include <QtMath>

#include <ctime>

barriers::barriers()
{
}
//梅林
Merlin::Merlin(){
    img.load(MERLIN2_PATH);
    img2.load(MERLIN2_PATH);
    x=GAMEWIDTH;
    y=315;
    rect.setWidth(img.width()-10);
    rect.setHeight(img.height()-3);
    rect.moveTo(x+5,y+3);
}
void Merlin::updateposition(){
    x-=SCENESCROLLSPEED;
    rect.moveTo(x+5,y+3);
}
bool Merlin::isout(){
    return x<-img.width();
}
int Merlin::collectdetection(QRect r){
    if(rect.intersects(r)){
        return 1;
    }
    else
        return 0;
}
QPixmap Merlin::getImg(int i){
    if(i==0){
        return img;
    }
    else
        return img2;
}
//咕哒子
gudazi::gudazi()
{
    img.load(GUDAZI_PATH);
    img2.load(GUDAZI_PATH);
    x=GAMEWIDTH;
    srand((unsigned int)time(NULL));
    u=rand()%(10000);
    y=189+169*qCos(t/50+u);
    rect.setWidth(img.width()-23);
    rect.setHeight(img.height()-11);
    rect.moveTo(x+10,y+6);
}
void gudazi::updateposition(){
    x-=SCENESCROLLSPEED;
    rect.moveTo(x+10,y+6);
}
void gudazi::updatebarrierpositionY(){
    t+=1;
    y=189+169*qCos(t/50+u);
}
bool gudazi::isout(){
    return x<-img.width();
}
int gudazi::collectdetection(QRect r){
    if(rect.intersects(r)){
        return 1;
    }
    else
        return 0;
}
QPixmap gudazi::getImg(int i){
    if(i==0){
        return img;
    }
    else
        return img2;
}

stone::stone(){
    img.load(STONE_PATH);
    x=GAMEWIDTH;
    y=rand()%(260)+40;
    rect.setWidth(img.width());
    rect.setHeight(img.height());
    rect.moveTo(x,y);
}
void stone::updateposition(){
    x-=SCENESCROLLSPEED;
    rect.moveTo(x,y);
}
bool stone::isout(){
    return x<-img.width();
}
int stone::collectdetection(QRect r){
    if(rect.intersects(r)){
        return 2;
    }
    else
        return 0;
}
QPixmap stone::getImg(int i){Q_UNUSED(i);
    return img;
}

qp::qp(int i){
    img.load(QP_PATH);
    x=GAMEWIDTH;
    if(i==1){
        x+=22;
        y=180;
    }
    if(i==2){
        y=rand()%240+50;
    }
    rect.setWidth(img.width());
    rect.setHeight(img.height());
    rect.moveTo(x,y);
}
void qp::updateposition(){
    x-=SCENESCROLLSPEED;
    rect.moveTo(x,y);
}
bool qp::isout(){
    return x<-img.width();
}
int qp::collectdetection(QRect r){
    if(rect.intersects(r)){
        return 3;
    }
    else
        return 0;
}
QPixmap qp::getImg(int i){Q_UNUSED(i);
    return img;
}









